package model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import pizza.admin.entity.Order;
import pizza.admin.entity.OrderPizza;
import pizza.admin.entity.Pizza;

/**
 * 
 * @author Radoslav Stoyanov
 *
 */
@XmlRootElement(name = "Order")
@XmlType(propOrder = {"id", "description", "address", "phone", "date", "user", "pizzas"})
public class XmlOrder {
	private Integer id;
	private String description;
	private String address;
	private String phone;
	private Date date;
	private XmlUser user;
	private Collection<XmlPizza> pizzas;

	public XmlOrder(Integer id, String description,
			String address, String phone, Date date,
			XmlUser user, Collection<XmlPizza> pizzas) {
		this.id = id;
		this.description = description;
		this.address = address;
		this.phone = phone;
		this.date = date;
		this.user = user;
		this.pizzas = pizzas;
	}

	public XmlOrder() {
		this.id = null;
		this.description = "";
		this.address = "";
		this.phone = "";
		this.date = null;
		this.user = null;
		this.pizzas = null;
	}

	public XmlOrder(Order order) {
		this.id = order.getId();
		this.description = order.getDescription();
		this.address = order.getAddress();
		this.phone = order.getPhone();
		this.date = order.getDate();

		XmlUser xmluser = new XmlUser(order.getUser());
		this.user = xmluser;
		
		this.pizzas = new ArrayList<XmlPizza>();
		for (OrderPizza orderpizza : order.getOrederPizas()) {
			Pizza pizza = orderpizza.getPizza();
			XmlPizza xmlpizza = new XmlPizza(pizza);
			for(int i=0; i<orderpizza.getCount(); i++){
				this.pizzas.add(xmlpizza);
			}
		}
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public XmlUser getUser() {
		return user;
	}

	public void setUser(XmlUser user) {
		this.user = user;
	}

	public Collection<XmlPizza> getPizzas() {
		return pizzas;
	}

	public void setPizzas(Collection<XmlPizza> pizzas) {
		this.pizzas = pizzas;
	}

}
